In the blog tutorial I learned that you could pass a model to a general view function in urls.py. I was wondering if there was a way to pass the model through urls.py to views.py as I want to run another method in views.py that would take a parameter from an attribute from models.py (specifically link). Currently I am using "r^test/$" but I want to use "r'^(?P<pk>d+)$'" to get the specific model to pass to views.py.
My urls.py looks like:
<pre class='prettyprint lang-py'> from django.conf.urls import url, include from . import views from django.views.generic import ListView, DetailView from catalog.models import dataset
urlpatterns = [ url(r'^$', ListView.as_view(queryset=dataset.objects.all(), template_name="catalog/catalog.html")), url(r'^Chicago/$', ListView.as_view(queryset=dataset.objects.all(), template_name="catalog/catalog.html")), url(r'^test/$', views.results, name = 'results'), url(r'^1$', views.resultLink, name = 'resultLink'), ]
my views.py look like: <pre class='prettyprint lang-py'> from django.shortcuts import render from sodapyTry import postIt from catalog.models import dataset from django.views.generic import ListView, DetailView
def index(request): return render(request, 'catalog/catalog.html') # Create your views here.
and my models.py looks like <pre class='prettyprint lang-py'> from django.db import models from jsonfield import JSONField
class dataset(models.Model): city = models.CharField(max_length=140) domain = models.CharField(max_length=140) link = models.CharField(max_length=140) filename = models.CharField(max_length=140)